package com.kgc.warehouse.bussness.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kgc.warehouse.bussness.dto.CustomerDTO;
import com.kgc.warehouse.bussness.entity.Customer;
import com.kgc.warehouse.bussness.mapper.CustomerMapper;
import com.kgc.warehouse.bussness.service.CustomerService;
import com.kgc.warehouse.system.common.CodeMsg;
import com.kgc.warehouse.system.common.ResponseResult;


import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author main
 * @description 针对表【bus_customer】的数据库操作Service实现
 * @createDate 2023-02-04 08:48:32
 */
@Service
@Transactional
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
        implements CustomerService {

    @Autowired(required = false)
    private CustomerMapper customerMapper;

    @Override
    public ResponseResult selectPage(CustomerDTO customerDTO) {

        Page<Customer> customerPage = new Page<>(customerDTO.getPage(), customerDTO.getLimit());
        LambdaQueryWrapper<Customer> lambda = new QueryWrapper<Customer>().lambda();


        lambda.eq(!StringUtils.isNullOrEmpty(customerDTO.getCustomername()), Customer::getCustomername, customerDTO.getCustomername())
                .eq(!StringUtils.isNullOrEmpty(customerDTO.getConnectionpersion()), Customer::getConnectionpersion, customerDTO.getConnectionpersion());
        customerMapper.selectPage(customerPage, lambda);

        long total = customerPage.getTotal();
        List<Customer> records = customerPage.getRecords();
        return new ResponseResult(records, total, CodeMsg.SUCCESS);
    }
}




